package org.qdao;

import java.util.ArrayList;
/**
 * 
 * @author 譚元吉
 * @since 2010/02/06 11:00:50
 */
public class DBEngineFactory {
	private static final String[] STOCK_ENGINE = { 
		"org.qdao.implement.mysql.MySqlDBEngine",
		"org.qdao.implement.oracle.OracleDBEngine"
		};

	private static ArrayList<IDBEngine> engines = new ArrayList<IDBEngine>();

	public static IDBEngine getEngine(DBConfig config) {
		for (String className : STOCK_ENGINE) {
			try {
				// Class.forName("org.qdao.implement.oracle.OracleDBEngine");
				Class.forName(className);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
		for (IDBEngine engine : engines) {
			if (engine.support(config)) {
				return engine;
			}
		}
		return null;
	}

	public static void register(IDBEngine engine) {
		engines.add(engine);
	}

	public static IDBEngine[] getAllEngines() {
		return engines.toArray(new IDBEngine[engines.size()]);
	}
}
